//
//  NumberInt.m
//  etionMisc
//
//  Created by wjxfhxy on 5/10/13.
//  Copyright (c) 2013 GuangZhouXuanWu. All rights reserved.
//

#import "XMSNumber.h"

@interface XMSNumber ()
{
    NSNumber *_number;
}

@property(nonatomic, retain) NSNumber *number;

@end

@implementation XMSNumber

@synthesize number = _number;

- (id)init
{
    self = [super init];

    _number = nil;

    return self;
}

- (BOOL)isEqual:(id)object
{
    if([object isKindOfClass:[XMSNumber class]])
        return [_number isEqual:((XMSNumber*)object).number];
    else if([object isKindOfClass:[NSNumber class]])
        return [_number isEqual:object];
    return NO;
}

- (NSUInteger)hash
{
    return [_number hash];
}

- (NSNumber *)toNSNumber
{
    return _number;
}

- (NSString *)toNSString
{
    return _number != nil? [_number stringValue] : @"";
}

- (NSComparisonResult)compare:(id)otherNumber
{
    if([otherNumber isKindOfClass:[XMSNumber class]])
        return [_number compare:((XMSNumber*)otherNumber).number];
    else if([otherNumber isKindOfClass:[NSNumber class]])
        return [_number compare:otherNumber];
    return NSOrderedSame;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeObject:_number forKey:@"cnumber"];
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
    _number = [[aDecoder decodeObjectForKey:@"cnumber"] retain];

    return self;
}

- (id)copyWithZone:(NSZone *)zone
{
    XMSNumber *number = [[self class] allocWithZone:zone];
    number.number = [_number copy];
    return number;
}

- (NSString *)description
{
    return [_number description];
}

-(NSString *)debugDescription
{
    return [_number debugDescription];
}

- (void)dealloc
{
    [_number release_mm];
    superdealloc_mm;
}

@end

@implementation XMSNumberInt

- (void)setIntValue:(NSInteger)intValue
{
    self.number = [NSNumber numberWithInteger:intValue];
}

- (NSInteger)intValue
{
    return [self.number integerValue];
}

+ (XMSNumberInt *)numberIntWithIntValue:(NSInteger)nInt
{
    XMSNumberInt *number = [[XMSNumberInt new] autorelease_mm];
    number.intValue = nInt;
    return number;
}

@end

@implementation XMSNumberLongLong

- (void)setLongLongValue:(long long)longLongValue
{
    self.number = [NSNumber numberWithLongLong:longLongValue];
}

- (long long)longLongValue
{
    return [self.number longLongValue];
}

+ (XMSNumberLongLong *)numberLongLongWithLongLongValue:(long long)nInt
{
    XMSNumberLongLong *number = [[XMSNumberLongLong new] autorelease_mm];
    number.longLongValue = nInt;
    return number;
}

@end

@implementation XMSNumberULongLong

- (void)setULongLongValue:(unsigned long long)uLongLongValue
{
    self.number = [NSNumber numberWithUnsignedLongLong:uLongLongValue];
}

- (unsigned long long)uLongLongValue
{
    return [self.number unsignedLongLongValue];
}

+ (XMSNumberULongLong *)numberULongLongWithULongLongValue:(unsigned long long)nInt
{
    XMSNumberULongLong *number = [[XMSNumberULongLong new] autorelease_mm];
    number.uLongLongValue = nInt;
    return number;
}

@end

@implementation XMSNumberFloat

- (void)setFloatValue:(float)floatValue
{
    self.number = [NSNumber numberWithFloat:floatValue];
}

- (float)floatValue
{
    return [self.number floatValue];
}

+ (XMSNumberFloat *)numberFloatWithFloatValue:(float)nFloat
{
    XMSNumberFloat *number = [[XMSNumberFloat new] autorelease_mm];
    number.floatValue = nFloat;
    return number;
}

@end

@implementation XMSNumberDouble

- (void)setDoubleValue:(double)doubleValue
{
    self.number = [NSNumber numberWithDouble:doubleValue];
}

- (double)doubleValue
{
    return [self.number doubleValue];
}

+ (XMSNumberDouble *)numberDoubleWithDoubleValue:(double)nDouble
{
    XMSNumberDouble *number = [[XMSNumberDouble new] autorelease_mm];
    number.doubleValue = nDouble;
    return number;
}

@end